/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminCarInfo: {
                cars: [],
                states:[],
                roomSubTypes:[],
                total: 0,
                records: 1,
                moreCondition: false,
                conditions: {
                    communityId: '',
                    paId: '',
                    leaseType: '',
                    ownerNameLike:'',
                    ownerTel:'',
                    carNum: '',
                    carNumLike: '',
                    carTypeCd:'1001',
                }
            }
        },
        _initMethod: function () {
            vc.emit('communityParkingTree', 'initCommunityParkingTree',{
                callName:'adminCar'
            });

        },
        _initEvent: function () {
            vc.on('adminCar', 'selectCommunity', function (_param) {
                $that.adminCarInfo.conditions.communityId = _param.communityId;
                $that.adminCarInfo.conditions.paId = '';
                $that.adminCarInfo.conditions.leaseType = '';
                $that._listAdminCommunityCars(DEFAULT_PAGE,DEFAULT_ROWS);
            });
            vc.on('adminCar', 'selectParkingArea', function (_param) {
                $that.adminCarInfo.conditions.communityId = '';
                $that.adminCarInfo.conditions.paId = _param.paId;
                $that.adminCarInfo.conditions.leaseType = '';
                $that._listAdminCommunityCars(DEFAULT_PAGE,DEFAULT_ROWS);

            });
            vc.on('adminCar', 'selectLeaseType', function (_param) {
                $that.adminCarInfo.conditions.communityId = '';
                $that.adminCarInfo.conditions.paId = '';
                $that.adminCarInfo.conditions.leaseType = _param.leaseType;
                $that._listAdminCommunityCars(DEFAULT_PAGE,DEFAULT_ROWS);
            });
            vc.on('adminCar', 'listAdminCar', function (_param) {
                $that._listCommunityPublicitys(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listAdminCommunityCars(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listAdminCommunityCars: function (_page, _rows) {
                $that.adminCarInfo.conditions.page = _page;
                $that.adminCarInfo.conditions.row = _rows;
                let param = {
                    params: $that.adminCarInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/owner.queryAdminOwnerCars',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminCarInfo.total = _json.total;
                        $that.adminCarInfo.records = _json.records;
                        $that.adminCarInfo.cars = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.adminCarInfo.records,
                            dataCount: $that.adminCarInfo.total,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
         
            //查询
            _queryCommunityPublicityMethod: function () {
                $that._listAdminCommunityCars(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _toCarDetailPage: function (_car) {
                vc.jumpToPage('/#/pages/car/adminCarDetail?memberId='+_car.carId);
            },
            _moreCondition: function () {
                if ($that.adminCarInfo.moreCondition) {
                    $that.adminCarInfo.moreCondition = false;
                } else {
                    $that.adminCarInfo.moreCondition = true;
                }
            },
            _computeTableDivWidth: function () {
                let mainWidth = document.getElementsByTagName('body')[0].clientWidth - document.getElementById('menu-nav').offsetWidth;
                let treeWidth = document.getElementsByClassName('room-floor-unit-tree')[0].offsetWidth;
                mainWidth = mainWidth - 20 - treeWidth - 15 - 20;
                //document.getElementsByClassName('hc-table-div')[0].style.width=mainWidth+'px';
                return mainWidth + 'px';
            },
            _getCarState: function (car) {
                if (car.state != null && car.state != '' && car.state != 'undefined' && car.state == '3003') {
                    return "到期";
                }
                let _carEndTime = new Date(car.endTime);
                if (_carEndTime.getTime() > new Date().getTime()) {
                    return "正常";
                }
                return "到期";
            },
        }
    });
})(window.vc);